About PThreadSorts
version: 1.0.0
last modified: August 8, 2000
PThread sorts is a sample based on the older sample MP Threaded Sort by Matthew Xavier Mora that took pictures and applied different sorting algorithms to them using MP Tasks.  This sample is similar but using POSIX Threads(pthreads) on Mac OS X instead.
Building the Code
The code was built using a standard Carbon Application(nib Based) project in project builder.
Restrictions
none.
Other Code Notes
The design is a C++ abstract base class which handles all the general setup and display operations for a picture that can be sorted.  Each specific sort derives off this class and overrides the Sort() method to sort the picture using its algorithm.  the InOrder() method is provided to do comparisons and the SwapPixels() method is provided for swapping pixels.  These routines will keep track of the number of swaps and comparisons for display in the window.  During construction, to allow sorting of the picture, each pixel is indexed in one array.  We can then just use this array to sort and scramble the picture by swapping the index and the actual pixel.  To make things clearer a second array keeps track pixel offsets from the base address of the picture so we can find the Nth pixel by adding the Nth index of this array to the base address of the picture.
Known Bugs
Currently the pthreads package under Mac OS X does not support cancellation points other than pthread_testcancel().  The pthreads standard specifies several other cancellation points including pthread_join which waits for the termintation of another thread in order to continue executing.  The lack of pthread_join() being a cancellation point causes a bug when cancelling the ThreadedQuickSort where it must wait for all the threads it's joining to terminate normally before it is actually canceled rather than having it cancel the thread at pthread_join() and then calling the cleanup routines which will cancel and join all the child threads.  This causes a delay when closing a ThreadedQuickSort picture.
Possible Future Enhancements
Add some more sorts.
Other Sources of Reference
none.
Version History
7/00-Created
Credits
Karl Groethe
Apple Developer Technical Support